
const fs = require('fs');

const useRouter = (app) => {
  //读取当前文件目录下所有的文件名字，返回 ['index.js', 'auth.router.js', 'user.router.js']
  const files = fs.readdirSync(__dirname);
  files.forEach(file => {
    if (file == 'index.js') return;
    const router = require(`./${file}`);
    app.use(router.routes());
    app.use(router.allowedMethods());
  });
  console.log(files);
}

module.exports = useRouter;